<?php

/*
 * Copyright by Aion-Germany.net | inZane
 * All Rights Reserved 2012-2013
 */
// needet includes
require_once'_libs/Smarty/Smarty.class.php';
require_once'_libs/mysql.php';
require_once'_libs/config.php';
if(file_exists('install/index.php')) {
    echo '<div id="installer">Please delete the Install Folder</div>';
}
$smarty->configLoad($lang . '/main.layout.php');
$sql = 'SELECT * FROM '.DB_CMS.'.website_settings';
$dbh = $connection->query($sql);
$settings = $dbh->fetch(PDO::FETCH_ASSOC);

$websitetitle		= $settings['title'];
$ip_server			= $settings['ip_server'];
$ip_teamspeak		= $settings['ip_teamspeak']; 
$port_gameserver	= $settings['gameserver_port'];
$port_loginserver	= $settings['loginserver_port'];
$port_teamspeak		= $settings['teamspeak_port'];

$main = new main;
// Check Loginstatus
$main->checkLogin();
// Load Stylesheets
$main->load_stylesheet('main.css');
$main->load_stylesheet('basic.css');
$main->load_stylesheet('ui-lightness/jquery-ui-1.8.22.custom.css');

$main->load_javascript('jquery.js');
$main->load_javascript('jquery.simplemodal.js');
$main->load_javascript('jquery-ui.js');
$main->load_javascript('datetimepicker.js');
// other stuff to crazy for u =)
if (!isset($_GET['page'])) {
    $_GET['page'] = 'index';
}
if (!isset($_GET["mod"])) {
    if (!file_exists("_modules/home/index.php")) {
        include"_modules/error404/index.php";
    } else {
        include"_modules/home/index.php";
    }
} elseif (!file_exists("_modules/" . $_GET["mod"] . "/" . $_GET["page"] . ".php")) {
    include"_modules/error404/index.php";
} else {
    include"_modules/" . $_GET["mod"] . "/" . $_GET["page"] . ".php";
}
if (isset($template)) {
    $smarty->assign('template', '_templates/' . $template);
} else {
    $smarty->assign('template', '_templates/error404/index.tpl');
}
if(isset($_GET['lang'])) {
    $_SESSION['lang'] = $_GET['lang'];
    echo'<meta http-equiv="refresh" content="0; URL=index.php">';
}
if (isset($_GET['mod'])) {
    if ($_GET['mod'] === 'logout') {
        unset($_SESSION);
        session_destroy();
        echo'<meta http-equiv="refresh" content="1; URL=login.php">';
    }
}

$access_level = $_SESSION['access_level'];
$sql = 'SELECT * FROM ' . DB_CMS . '.website_navigation 
			WHERE access_level <= "' . $access_level . '" 
			ORDER BY access_level';
$navigation = $connection->query($sql)->fetchAll(PDO::FETCH_ASSOC);
$sql = 'SELECT * FROM ' . DB_CMS . '.website_modules WHERE access_level = :level';
$stm = $connection->prepare($sql);
foreach ($navigation as $key => $cat) {
    $stm->bindValue(':level', $cat['access_level']);
    $stm->execute();
    $cat['links'] = $stm->fetchAll(PDO::FETCH_ASSOC);
    $navigation[$key] = $cat;
}

$rights = $main->getRights($_SESSION['id'], 1);

$sql = 'SELECT * FROM '.DB_CMS.'.website_languages';
$dbh = $connection->query($sql);
while($row = $dbh->fetch(PDO::FETCH_ASSOC)) {
    $mylang[] = $row;
}

$smarty->assign('mylang', $mylang);
$smarty->assign('rights', $rights);
$smarty->assign('navi_cats', $navigation);
$smarty->assign('websitetitle', $websitetitle);
$smarty->assign('breadcrumb', $breadcrumb);
$smarty->assign('username', $_SESSION['name']);

$smarty->display('_layout/' . $theme . '/index.tpl');




if ($debug === 1) {
    echo '<pre class="debug">';
    echo '<b>Session</b><br /><br />';
    print_r($_SESSION);
    echo '</pre>';

    echo '<pre class="debug">';
    echo '<b>SQL</b><br /><br />';
    print_r($dbh);
    print_r($stm);
    echo '</pre>';

    echo '<pre class="debug">';
    echo '<b>loop</b><br /><br />';
    print_r($value);
    echo '</pre>';
}
?>